<!DOCTYPE html>
<html lang="en">


{include file="Public/head"}

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

	{include file='Public:header'}
	{include file='Public:menu2'}



	<!-- 内容区域 -->
	<div class="tpl-content-wrapper">
		<div class="row-content am-cf">
			<div class="row">
				<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
					<div class="widget am-cf">
						<div class="widget-head am-cf">
							<div class="widget-title  am-cf">广告列表</div>
						</div>
						<div class="widget-body  am-fr">

							<form class="navbar-form form-inline" action="{:url('Admin/Ad/adList')}" method="post">
							<div class="form-group">
								<input type="text" name="keywords" class="form-control" placeholder="请输入广告名称">
							</div>
							<div class="form-group">
								<select name="pid" class="form-control">
									<option value="0">==查看所有==</option>
                                    {volist name='ad_position_list' id='item'}
                                    <option value="{$item.position_id}">{$item.position_name}</option>
                                    {/volist}
								</select>
							</div>
							<button type="submit" class="btn btn-primary">查询</button>
							<div class="form-group pull-right">
								<a href="{:url('Admin/Ad/adAdd')}" class="btn btn-primary pull-right"><i class="fa fa-plus"></i> 新增广告</a>
							</div>
							</form>

                            <div class="widget-body  am-fr">



                            <div class="am-u-sm-12">
								<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
									<thead>
									<tr>
										<th>广告id</th>
										<th>广告位置</th>
										<th>广告名称</th>
										<th>广告图片</th>
										<th>广告链接</th>
										<th>是否显示</th>
										<th>排序</th>
										<th>操作</th>
									</tr>
									</thead>
									<tbody>
									{volist name='res' id='vo'}
									<tr class="gradeX">
										<td>{$vo.ad_id}</td>
										<td>{$ad_position_list[$vo.pid]['position_name']}</td>
										<td>{$vo.ad_name}</td>
										<td><img alt="" src="{$vo.ad_code}" width="80px" height="50px"></td>
										<td>{$vo.ad_link}</td>

                                        <td>
                                            {if condition='$vo.enabled eq 1'}
                                            <img width="20" height="20" src="/assets/img/yes.png"  onclick="display(this)" displayid="{$vo.ad_id}"/>

                                            {else}
                                            <img width="20" height="20" src="/assets/img/cancel.png"  onclick="display(this)" displayid="{$vo.ad_id}"/>
                                            {/if}
                                        </td>
                                        <td>
                                            <input type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onblur="updateSort(this)" orderid="{$vo.ad_id}" size="4" value="{$vo.orderby}" class="input-sm" />
                                        </td>
										<td>
											<div class="tpl-table-black-operation">
												<a href="{:Url('ad_edit')}?ad_id={$vo.ad_id}">
													<i class="am-icon-pencil"></i> 编辑
												</a>
												<a onclick="del_button('{$vo.ad_id}','{$vo.ad_code}');" href="javascript:void(0);" href="javascript:;" class="tpl-table-black-operation-del">
													<i class="fa fa-trash-o"></i> 删除
												</a>
											</div>
										</td>
									</tr>
									{/volist}
									<!-- more data -->
									</tbody>
								</table>
							</div>
							<div class="am-u-lg-10 am-cf">

								<div class="am-fr">
									<ul class="am-pagination tpl-pagination">
									{$res->render()}
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</div>

</body>
{include file='Public:script'}
<script>
	//排序更改
	function updateSort(e) {
        var ad_id =$(e).attr('orderid');
        var orderby =$(e).prop('value');
        $.ajax({
            url:'orderchange', /*去过那个php文件*/
            type:'POST',  /*提交方式*/
            data:{
                'ad_id':ad_id,
				'orderby':orderby
            },
            cache: false,
            dataType: "json",
            success:function(data){
                if (data['code'] == 1) {
                    alert(data['message'])
                } else if (data['code'] == 200) {
                    alert(data['message'])
                }
            }
        })
    }

	//是否新窗口打开改变
	function display(e) {
        if($(e).attr('src').indexOf("cancel.png") > 0 )
        {
            src = '/assets/img/yes.png';
            var value = 1;
        }else{
            src = '/assets/img/cancel.png';
            var value = 0;
        }
        var ad_id = $(e).attr('winid');

        $.ajax({
            url:'winopen', /*去过那个php文件*/
            type:'POST',  /*提交方式*/
            data:{
                'ad_id':ad_id,
				'target':value
			},
            cache: false,
            dataType: "json",
            success:function(xhr){
                $(e).attr('src',src);
            }
        })
    }
	//是否显示改变
    function display(e) {
            if($(e).attr('src').indexOf("cancel.png") > 0 )
            {
                src = '/assets/img/yes.png';
                var value = 1;
            }else{
                src = '/assets/img/cancel.png';
                var value = 0;
            }
            var ad_id = $(e).attr('displayid');
            $.ajax({
                url:'showopen', /*去过那个php文件*/
                type:'POST',  /*提交方式*/
                data:{
                    'ad_id':ad_id,
                    'enabled':value
                },
                cache: false,
                dataType: "json",
                success:function(xhr){
                    $(e).attr('src',src);
                }
            })

    }

    //删除
	function del_button(e,v) {
        var result = confirm('是否删除此作品');
        if (result) {
            $.ajax({
                type: "post",
                url: "del",
                async: true,
                data: {
					'ad_id':e,
					'ad_code':v
                },
                dataType: "json",
                success: function (data) {
                    if (data['code'] == 1) {
                        alert(data['message'])
                    } else if (data['code'] == 200) {
                        alert(data['message'])
                    }
                    window.location.reload()
                },
            });
        }else {
            window.location.reload()
        }
    }
</script>
</html>